package com.wx.fresh.platform.controller;

import com.wx.fresh.common.pojo.CUser;
import com.wx.fresh.common.util.CommonResult;
import com.wx.fresh.platform.vo.PlatformUserVo;
import com.wx.fresh.user.api.UserFeignClient;
import com.wx.fresh.user.dto.PlatformUserDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author:srf
 * @Data: 2022/4/20
 */
@Api(tags = "平台用户管理", value = "平台用户管理")
@RestController
@RequestMapping("platformUser")//平台用户管理
public class PlatformUserController {

    @Autowired
    private UserFeignClient userFeignClient;

    @ApiOperation(value = "平台查询用户")
    @GetMapping("/platformFindAll")//平台用户查询
    public CommonResult findAll(@RequestBody PlatformUserVo platformUserVo) {
        PlatformUserDto platformUserDto = new PlatformUserDto();
        BeanUtils.copyProperties(platformUserVo, platformUserDto);
        List<CUser> list = userFeignClient.FindAll(platformUserDto);
        return CommonResult.success(list);
    }

    @ApiOperation(value = "根据指定id查询指定用户信息")
    @GetMapping("/platformFindById")
    public CommonResult<PlatformUserVo> FindById(@RequestParam("id") Long id) {
        PlatformUserDto platformUserDto = userFeignClient.FindById(id);
        PlatformUserVo platformUserVo = new PlatformUserVo();
        BeanUtils.copyProperties(platformUserVo, platformUserDto);
        return CommonResult.success(platformUserVo);
    }

    @ApiOperation(value = "平台编辑用户")
    @PostMapping("/platformEdit")//平台用户编辑
    public CommonResult Edit(PlatformUserVo platformUserVo) {
        return null;
    }


    @ApiOperation(value = "平台删除用户")
    @ApiImplicitParam(name = "id", value = "用户id", required = true, paramType = "int")
    @PostMapping("/platformDelete")//平台用户删除
    public CommonResult delete(@RequestParam("id") Long id) {
        int delete = userFeignClient.Delete(id);
        return CommonResult.success("success");
    }
}
